/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fvm;

import algebra.Point2d;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author BIM1LA
 */
public class FVModelData {
    
    
    ArrayList<ArrayList<FVElement>> fvelements; //Finite Volume Elemente
    int n,m;
    public double dx;
    public double dy;
    public double sizex,sizey;
    public double maxbc=12,minbc=8;
    
    public FVModelData(int n, int m,double sizex, double sizey,double dx, double dy){
    
        this.n = n;
        this.m = m;
        
        this.sizex = sizex;
        this.sizey = sizey;
        
        this.dx = dx;
        this.dy = dy;
        
        
    fvelements = new ArrayList<>(n);
    
    initModelData();
    
    
    }
    
    private void initModelData(){
    
               
        
        for (int i  = 0; i <= m; i++) {
            
            fvelements.add(new ArrayList<FVElement>(m));
            
            for (int j = 0; j <= n; j++) {
              
//                Point2d p2d = new Point2d(dx/2+j*dx, (dy/2+i*dy));
                Point2d p2d = new Point2d(j*dx, i*dy);
                
                fvelements.get(i).add(new FVElement(p2d,dx,dy));
                if(i == 0){
                    
                    //unten
  
                    fvelements.get(i).get(j).setnoflow(true);
                    //fvelements.get(i).get(j).setboundary(true,0);
                    
                }
                if(i == m){
                
                    
                    //oben

                                    fvelements.get(i).get(j).setnoflow(true);
//                                    fvelements.get(i).get(j).setboundary(true, 8);

                }
                if(j == 0){
                
                    //links

                     fvelements.get(i).get(j).setboundary(true, 8);
//                        fvelements.get(i).get(j).setnoflow(true);
                
                }
                if(j == n){
                

                     
                          
                            fvelements.get(i).get(j).setboundary(true, 12);
                

                }
                
           
                
            }
          }
        
          for (int i  = 0; i <= m; i++) {
            
            for (int j = 0; j <= n; j++) {
    
                FVElement temp = fvelements.get(i).get(j);
                temp.seti(m-i);
                temp.setj(j);
                
                if(j>0) temp.setWestNeigh(fvelements.get(i).get(j-1));
                if(j<n) temp.setEastNeigh(fvelements.get(i).get(j+1));
                if(i<m) temp.setNorthNeigh(fvelements.get(i+1).get(j));
                if(i>0) temp.setSouthNeigh(fvelements.get(i-1).get(j));
                
                
            }
          }
    }
    
    
    public ArrayList<ArrayList<FVElement>> getElements(){return fvelements;}
    
    public FVElement getElement(int i, int j){
        
        if(i > m||j>n) return null;
        else
            return fvelements.get(m-i).get(j);
        
    }
            
    
}
